package com.train.common.utils;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.train.common.enums.ResultEnum;
import com.train.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;

@Slf4j
public class AssertUtil {
    private AssertUtil() {

    }

    public static void isEmptyOrUndefined(String str) {
        if (StrUtil.isEmptyOrUndefined(str)) {
            throw new BusinessException(ResultEnum.PARAM_VALID_FAIL);
        }
    }

    public static void isEmptyOrUndefined(String str, String message) {
        if (StrUtil.isEmptyOrUndefined(str)) {
            throw new BusinessException(ResultEnum.PARAM_VALID_FAIL);
        }
    }

    public static void isNull(Object obj, String message) {
        if (ObjectUtil.isNull(obj)) {
            throw new BusinessException(ResultEnum.PARAM_VALID_FAIL);
        }
    }

    public static void isNull(Object obj) {
        if (ObjectUtil.isNull(obj)) {
            throw new BusinessException(ResultEnum.DATA_IS_NOT_EXIST);
        }
    }

    public static void isNull(Object obj, String code, String message) {
        if (ObjectUtil.isNull(obj)) {
            throw new BusinessException(message);
        }
    }


    public static void isEmpty(Collection e, String message) {
        if (ObjectUtil.isNull(e) || e.isEmpty()) {
            throw new BusinessException(message);
        }
    }

    public static void isEmpty(Collection e, String code, String message) {
        if (ObjectUtil.isNull(e) || e.isEmpty()) {
            throw new BusinessException(message);
        }
    }

    public static void isTrue(boolean isTrue, String message) {
        if (isTrue) {
            throw new BusinessException(message);
        }
    }

    public static void isFalse(boolean isFalse, String message) {
        if (!isFalse) {
            throw new BusinessException( message);
        }
    }

    public static void isTrue(boolean isTrue, String code, String message) {
        if (isTrue) {
            throw new BusinessException( message);
        }
    }

    public static void isFalse(boolean isFalse, String code, String message) {
        if (!isFalse) {
            throw new BusinessException(message);
        }
    }
}
